package com.yc.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.R_Code;
import com.yc.Result;
import com.yc.entities.BloodSugarBed;
import com.yc.entities.custom.CustomBarCodeResponseBean;
import com.yc.entities.custom.CustomBedInfoQueryResponseBean;
import com.yc.entities.custom.CustomBedQueryResponseBean;
import com.yc.mapper.BloodSugarBedMapper;
import com.yc.service.BloodSugarBedService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 院内床位信息表 服务实现类
 * </p>
 *
 * @author kuakha
 * @since 2021-04-07
 */
@Service
public class BloodSugarBedServiceImpl extends ServiceImpl<BloodSugarBedMapper, BloodSugarBed> implements BloodSugarBedService {

    @Override
    public Result getAllBedNum(Integer deanId, Integer departmentId, Integer current, Integer size) {
        Page<Integer> page = new Page<>(current == null ? 0 : current, size == null ? 10 : size);
        List<CustomBedQueryResponseBean> allRoleInfo = this.baseMapper.getAllBedNum(page, deanId, departmentId);
        if (page.getTotal() >= 1) {
            return Result.ok().total((int) page.getTotal()).data(allRoleInfo);
        } else {
            return Result.ok().code(R_Code.R_NULL_DATA_FAIL);
        }
    }

    @Override
    public Result getBedInfo(Integer deanId, Integer departmentId, Integer current, Integer size) {
        Page<Integer> page = new Page<>(current == null ? 0 : current, size == null ? 10 : size);
        List<CustomBedInfoQueryResponseBean> allRoleInfo = this.baseMapper.getBedInfo(page, deanId, departmentId);
        if (allRoleInfo.size() >= 1) {
            return Result.ok().total((int) page.getTotal()).data(allRoleInfo);
        } else {
            return Result.ok().code(R_Code.R_NULL_DATA_FAIL);
        }
    }

    @Override
    public Result getAllBedNumBox(Integer deanId, Integer departmentId) {
        List<CustomBedQueryResponseBean> allRoleInfo = this.baseMapper.getAllBedNumBox(deanId, departmentId);
        if (allRoleInfo.size() >= 1) {
            allRoleInfo.removeIf(f1 -> "1".equals(f1.getBedStatus()));
            return Result.ok().data(allRoleInfo);
        } else {
            return Result.ok().code(R_Code.R_NULL_DATA_FAIL);
        }
    }
}
